package com.cxw.healthserver.controller

import com.cxw.healthserver.annotation.PassToken
import com.cxw.healthserver.bean.Doctor
import com.cxw.healthserver.constant.Constants
import com.cxw.healthserver.entity.User
import com.cxw.healthserver.request.LoginRequest
import com.cxw.healthserver.resolver.CurrentUser
import com.cxw.healthserver.response.BaseResponse
import com.cxw.healthserver.response.LoginResponse
import com.cxw.healthserver.response.UserInfoResponse
import com.cxw.healthserver.service.AuthService
import com.cxw.healthserver.service.UserService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*


/**
 * @createTime 2024/6/16 11:41
 * @author 崔兴旺
 * @description
 */
@RestController
@RequestMapping("api")
class UserController {

    @Autowired
    private lateinit var authService: AuthService

    @Autowired
    private lateinit var userService: UserService

    /**
     * 登录
     */
    @PassToken
    @PostMapping("login", produces = [Constants.produces])
    fun login(@RequestBody loginRequest: LoginRequest): BaseResponse<LoginResponse> {
        return authService.login(loginRequest.username, loginRequest.password)
    }

    /**
     * 获取用户信息
     */
    @PostMapping("getUserInfo", produces = [Constants.produces])
    fun getUserInfo(@CurrentUser user: User): BaseResponse<UserInfoResponse> {
        return BaseResponse.success(UserInfoResponse().apply {
            this.userid = user.id
            this.username = user.username
            this.realname = user.realname
        })
    }



    /**
     * 获取医生列表
     */
    @GetMapping("doctors", produces = [Constants.produces])
    fun getDoctors(): BaseResponse<MutableList<Doctor>> {
        return BaseResponse.success(
            userService.getDoctors()
        )
    }
}